<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <title>订单</title>
    <style>
        div {
            text-align: center;
        }

        table {
            display: inline-block;
        }

        table, tr, th, td {
            border: 1px solid #5fbdcb;
        }

        table {
            border-collapse: collapse;
        }
    </style>
</head>
<body>
<div>
    <table></table>
    <a href="UserPage.jsp">返回</a>
</div>
<script src="https://lib.sinaapp.com/js/jquery/2.0.2/jquery-2.0.2.min.js"></script>
<script>
    $(function () {
        $.ajax({
            url: "http://localhost:8080/order.do",
            type: "post",
            data: {
                method: 'userOrder'
            },
            dataType: "text",
            success: function (data) {
                let table = document.querySelector('table');
                let parse = JSON.parse(data);
                if (parse.length === 0) {
                    alert('你还没有订单，请先下单');
                    window.location.href = 'UserPage.jsp';
                } else {
                    for (let i = 0; i < parse.length; i++) {
                        let tr = document.createElement('tr');
                        table.appendChild(tr);
                        let th1 = document.createElement('th');
                        th1.innerText = '店铺名：'
                        tr.appendChild(th1);
                        let td1 = document.createElement('td');
                        td1.innerText = parse[i].storeName;
                        tr.appendChild(td1);
                        let th2 = document.createElement('th');
                        th2.innerText = '下单的菜品：'
                        tr.appendChild(th2);
                        let td2 = document.createElement('td');
                        td2.innerText = parse[i].dishName;
                        tr.appendChild(td2);
                        let th3 = document.createElement('th');
                        th3.innerText = '状态：'
                        tr.appendChild(th3);
                        let td3 = document.createElement('td');
                        if (parse[i].status === 0) {
                            td3.innerText = '未接单';
                        }
                        if (parse[i].status === 1) {
                            td3.innerText = '已接单';
                        }
                        if (parse[i].status === 2) {
                            td3.innerText = '完成';
                        }
                        tr.appendChild(td3);
                        let th4 = document.createElement('th');
                        th4.innerText = '成交金额：'
                        tr.appendChild(th4);
                        let td4 = document.createElement('td');
                        td4.innerText = parse[i].money;
                        tr.appendChild(td4);
                        let td6 = document.createElement('td');
                        tr.appendChild(td6);
                        if (parse[i].status === 1) {
                            let a2 = document.createElement('a');
                            a2.innerText = '修改为完成';
                            a2.href = 'UserModifyOrderStatus.jsp?orderId=' + parse[i].orderId + '&storeId=' + parse[i].storeId;
                            td6.appendChild(a2);
                        } else {
                            td6.innerText = '';
                        }
                    }
                }
            }
        })
    })
</script>
</body>
</html>
